<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>黑马旅游网-登录</title>  
    <link rel="stylesheet" type="text/css" href="css/common.css">
    <link rel="stylesheet" type="text/css" href="css/login.css">
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
      <!--导入angularJS文件-->
    <script src="js/angular.min.js"></script>
	<!--导入jquery-->
	<script src="js/jquery-3.3.1.js"></script>
	<script>
		/**验证用户名*/
		function checkUsername() {
			var username = $("username").val();
			var reg_username=/^\w{8,20}$/;
			var flag = reg_username.test(username);
			if (flag){
				$("#username").css("border","");
				return true;
			}else{
				$("#username").css("border","1px solid red")
				return false;
			}

		};
		/**验证密码*/
		function checkPassword() {
			var password = $("#password").val();
			var reg_password=/^\w{6,20}$/;
			var flag = reg_password.test(password);
			if (flag){
				$("#password").css("border","");
				return true;
			}else{
				$("#password").css("border","1px solid red")
				return false;
			}

		};
		function checkCode(){
			var code = $("#check").val();
			if (code!=null){
				return true;
			}
			return false;
		}
		/**离焦事件的验证*/
		$("#username").blur(checkUsername);
		$("#password").blur(checkPassword);
		$("#check").blur(checkCode);

		$(function () {
			$("#login").click(function () {
					var flag = checkUsername()&&checkPassword()&&checkCode();
					if (flag){
						//验证成功
						$.post("user/loginServlet",$("#loginForm").serialize(),function (data) {
							//flag:false,errorMsg:"注册失败"
							if (data.flag){
								//登陆成功
								location.href="index.html";
							}else{
								//登录失败
								$("#errorMsg").html(data.errorMsg);
							}

						});
					}else{
						//验证失败
						$("#errorMsg").html("用户名或密码格式错误")
					}
					return false;
				});

		})
	</script>
</head>

<body>
<!--引入头部-->
<div id="header"></div>
    <!-- 头部 end -->
    <section id="login_wrap">
        <div class="fullscreen-bg" style="background: url(images/login_bg.png);height: 532px;">
        	
        </div>
        <div class="login-box">
        	<div class="title">
        		<img src="images/login_logo.png" alt="">
        		<span>欢迎登录黑马旅游账户</span>
        	</div>
        	<div class="login_inner">
				
				<!--登录错误提示消息-->
        		<div id="errorMsg" class="alert alert-danger" ></div>
				<form id="loginForm" action="" method="post" accept-charset="utf-8">
        			<input type="hidden" name="action" value="login"/>
					<input name="username" type="text" placeholder="请输入账号" autocomplete="off" id="username">
        			<input name="password" type="text" placeholder="请输入密码" autocomplete="off" id="password">
        			<div class="verify">
					<input name="check" type="text" placeholder="请输入验证码" autocomplete="off" id="check">
					<span><img src="checkCode" alt="" onclick="changeCheckCode(this)"></span>
					<script type="text/javascript">
						//图片点击事件
						function changeCheckCode(img) {
							img.src="checkCode?"+new Date().getTime();
						}
					</script>
			</div>
			<div class="submit_btn">
        				<button type="button" id="login">登录</button>
        				<div class="auto_login">
        					<input type="checkbox" name="" class="checkbox">
        					<span>自动登录</span>
        				</div>        				
        			</div>        			       		
        		</form>
        		<div class="reg">没有账户？<a href="javascript:;">立即注册</a></div>
        	</div>
        </div>
    </section>
    <!--引入尾部-->
    <div id="footer"></div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="js/jquery-1.11.0.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
    <!--导入布局js，共享header和footer-->
    <script type="text/javascript" src="js/include.js"></script>
</body>

</html>